﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace Tommy
{
    public partial class UILoader : FormEx,IUILoader
    {

        delegate void UpdateStepsTextEvent(string text);
        delegate void UpdateStepsValueEvent(int value);
        delegate void FormEvent();
        public UILoader()
        {
            InitializeComponent();
        }


        public void UpdateProgressText(string text)
        {
            if (labelInitializing.InvokeRequired)
            {
                UpdateStepsTextEvent call = new UpdateStepsTextEvent(UpdateProgressText);
                Invoke(call, new object[] { text });

            }
            else
            {
                labelInitializing.Text = text;

            }
        }

        public void UpdateProgressValue(int value)
        {
            if (pbarInitializing.InvokeRequired)
            {
                UpdateStepsValueEvent valueChanged = new UpdateStepsValueEvent(UpdateProgressValue);
                Invoke(valueChanged, new object[] { value });

            }
            else
            {
                pbarInitializing.Value = value;
            }
        }

        public void CloseEx()
        {
            if (this.InvokeRequired)
            {
                FormEvent closeHappend = new FormEvent(Close);
                Invoke(closeHappend);
            }
            else
            {
                base.Close();
            }
        }

        public void ShowEx()
        {
            if (this.InvokeRequired)
            {
                FormEvent showHappend = new FormEvent(Close);
                Invoke(showHappend);
            }
            else
            {
                Show();
            }
        }

        

       
    }
}



